" --------------------------------------------------------------------------
" Basic settings
" --------------------------------------------------------------------------
set nu                                      " set row number
set nocompatible                            " be iMproved
set t_Co=256                                " vim color scheme
set cursorline                              " highlight the current line
set showmatch                               " show mathced brackets
set autoindent smartindent                  " smart auto-indent
set foldmethod=indent                       " default indent mode
set showcmd                                 " show commands that not finished
set directory=/tmp                          " set directory for .swp files
set autochdir                               " automatically change directory
set incsearch hlsearch ignorecase smartcase " settings for search
set title                                   " enable dynamic title

" ESC
inoremap jk <Esc>
inoremap <c-[> <Esc>

" fix bugs of vim (eg. taglist) on iTerm2
" solution: iTerm2: Preferences -> Profiles -> Terminal -> uncheck "Disable
" session-initiated window resizing"

" using 4 spaces to replace tab
set expandtab smarttab
set shiftwidth=4
set softtabstop=4

" dealing with copy-paste (avoid auto-indent when paste codes)
" or use =:set paste= and =:set nopaste=
set pastetoggle=<F2>

" language spell checking
autocmd FileType tex setlocal spell spelllang=en_us
autocmd BufNewFile,BufRead *.txt setlocal spell spelllang=en_us

" color schemes
if ! has("gui_running")
    colorscheme lucius
    LuciusDark
else  " /gvim/
    colorscheme lucius
    LuciusLight
    set guioptions=a  "remove menus, using clipboard instead of primary
    set guicursor=a:blinkwait600-blinkoff600-blinkon600 "blink frequency
endif

" status line
set laststatus=2
set statusline=%<%h%m%r\ %f%=[%{&filetype},%{&fileencoding},%{&fileformat}]%k\ %-14.(%l/%L,%c%V%)\ %P

" backup
set backup
set backupdir=/tmp

" set cursor to the last position
autocmd BufReadPost *
    \if line("'\"") > 0 && line("'\"") <= line("$") |
        \exe "normal g`\"" |
    \endif

" auto remove extra spaces
autocmd BufWritePre * :%s/\s\+$//e


" --------------------------------------------------------------------------
"  Key maps
" --------------------------------------------------------------------------
nnoremap <F8> :vertical wincmd gf<CR>
nnoremap <Leader>nl :nohlsearch<CR>


" --------------------------------------------------------------------------
" Plugins
" --------------------------------------------------------------------------

" Vundle
" -----------------
filetype off				" required
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'VundleVim/Vundle.vim'
" List of installed plugins:
" repos on github
  Plugin 'LaTeX-Box-Team/LaTeX-Box'
  Plugin 'djoshea/vim-matlab'
" vim-scripts repos
  Plugin 'taglist.vim'
  Plugin 'jamessan/vim-gnupg'
  Plugin 'scrooloose/nerdcommenter'
" All of your Plugins must be added before the following line
call vundle#end()            " required
filetype plugin indent on    " required
" Help
" :PluginList          - list configured bundles
" :PluginInstall       - install(update) bundles
" :PluginSearch foo    - search(or refresh cache first) for foo
" :PluginClean         - confirm(or auto-approve) removal of unused bundles
" see :h vundle for more details or wiki for FAQ

" Taglist
" -----------------
let Tlist_Enable_Fold_Column=0
let Tlist_Exit_OnlyWindow=1
let Tlist_GainFocus_On_ToggleOpen=1
let Tlist_Show_One_File=1
let tlist_tex_settings   = 'latex;s:sections;g:graphics;l:labels'
let tlist_matlab_settings = 'matlab;f:functions'
" 'T' opens/closes the TagList window
nnoremap <Leader>t :TlistToggle<CR>


" --------------------------------------------------------------------------
" misc
" --------------------------------------------------------------------------
syntax on
